﻿using System;
using System.Collections.Specialized;

namespace BLL.Utility
{
    public class AnalyseJqGridQueryString
    {
        protected NameValueCollection QueryString { get; set; }

        protected int? CurrentPage { get; set; }

        public AnalyseJqGridQueryString(NameValueCollection queryString)
        {
            QueryString = queryString;
        }

        public AnalyseJqGridQueryString(NameValueCollection queryString, int? currentPage)
        {
            QueryString = queryString;
            CurrentPage = currentPage;
        }

        public PageInfo GetPageInfo()
        {
            int currentPage = CurrentPage == null ? int.Parse(QueryString["page"]) : CurrentPage.Value;
            int pageSize = int.Parse(QueryString["rows"]);
            return new PageInfo(currentPage, pageSize);
        }

        public Tuple<string, string> GetSortField()
        {
            var sortField = QueryString["sidx"];
            var sortType = QueryString["sord"];
            return new Tuple<string, string>(sortField, sortType);
        }

    }
}